package com.braveman.im.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.braveman.im.R;
import com.braveman.im.bean.EditPersonInfoBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by 昊昊 on 2017/10/13.
 */

public class EdTextActivity extends BaseActivity {
    private EditText edContent;
    private int etType;

    @Override
    protected void initTitleBar() {
        //标题以及右侧按钮
        String name = "";
        switch (etType) {
            case 1://
                name = "编辑真实姓名";
                break;
            case 2:
                name = "修改微信";
                break;
            case 3:
                name = "修改QQ";
                break;
            case 4:
                name = "修改手机号码";
                break;
            case 5:
                name = "修改邮箱地址";
                break;
            case 6:
                name = "修改生日信息";
                break;
            case 7:
                name = "个性签名";
                break;
            case 8:
                name = "公司名称";
                break;
            case 9:
                name = "您的职务";
                break;
            case 10:
                name = "公司电话";
                break;
            case 11:
                name = "详细地址";
                break;
            case 12:
                name = "期望结识";
                break;
            case 13:
                name = "您的性别";
                break;
        }
        mTitleBarView.setTitleText(name).addActions(new TitleBarView.Action("保存") {

            @Override
            public void performAction(View view) {
//                Intent intent = new Intent();
//                intent.putExtra("date_name", edName.getText().toString());//接收Edittext输入的值，并将数值通过键值对的方式传递给Activity
//                setResult(RESULT_OK, intent);//SET返回的数值
//                ActivityUtils.finishActivity(EdTextActivity.this);//带数据的跳转页面
                if (TextUtils.isEmpty(edContent.getText().toString().trim())) {
                    UIUtils.showToast("请输入修改的内容");
                    return;
                }
                EditPersonInfoBean editPersonInfoBean = new EditPersonInfoBean();
                switch (etType) {
                    case 1:
                        editPersonInfoBean.name = edContent.getText().toString().trim();
                        break;
                    case 2:
                        editPersonInfoBean.wechatId = edContent.getText().toString().trim();
                        break;
                    case 3:
                        editPersonInfoBean.qq = edContent.getText().toString().trim();
                        break;
                    case 4:
                        editPersonInfoBean.mobile = edContent.getText().toString().trim();
                        break;
                    case 5:
                        editPersonInfoBean.email = edContent.getText().toString().trim();
                        break;
                    case 6:
                        editPersonInfoBean.birth = edContent.getText().toString().trim();
                        break;
                    case 7:
                        editPersonInfoBean.personalSignature = edContent.getText().toString().trim();
                        break;
                    case 8:
                        editPersonInfoBean.corpName = edContent.getText().toString().trim();
                        break;
                    case 9:
                        editPersonInfoBean.corpJob = edContent.getText().toString().trim();
                        break;
                    case 10:
                        editPersonInfoBean.corpPhone = edContent.getText().toString().trim();
                        break;
                    case 11:
                        editPersonInfoBean.corpDetailedAddress = edContent.getText().toString().trim();//详细地址
                        break;
                    case 12:
                        editPersonInfoBean.lookForwardToMeet = edContent.getText().toString().trim();
                        break;
                    case 13:
                        editPersonInfoBean.gender = edContent.getText().toString().trim();
                        break;
                }
                // TODO: 2017/11/6
                showLoadingDialog();
                ApiManager.getApi().editPersonInfo(editPersonInfoBean).enqueue(new NetCallBack<EditPersonInfoBean>() {
                    @Override
                    protected void onSuccess(Call<EditPersonInfoBean> call, Response<EditPersonInfoBean> response) {
                        if (response.body() != null) {
                            Intent intent = new Intent();
                            String resul = edContent.getText().toString().trim();
                            intent.putExtra("date_name", resul);
                            setResult(RESULT_OK, intent);
                            ActivityUtils.finishActivity(EdTextActivity.this);
                        }
                    }

                    @Override
                    protected void hiddenProgress() {
                        hideLodingDialog();
                    }
                });


            }
        }).setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(EdTextActivity.this);
            }
        });


    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_edtext;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        etType = callIntent.getIntExtra("etType", -1);
    }

    @Override
    protected void initChildView() {
        edContent = (EditText) findViewById(R.id.et_activity);
    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    protected void setChildViewListener() {

    }
}
